Imports System.ComponentModel
Imports Aricie.DNN.UI.Attributes
Imports Aricie.DNN.ComponentModel
Imports System.Web.UI.WebControls
Imports Aricie.DNN.Services
Imports System.IO
Imports Aricie.DNN.Modules.LuceneSearch.Business
Imports Aricie.ComponentModel
Imports Aricie.DNN.Modules.LuceneSearch.ModuleProviders
Imports DotNetNuke.Entities.Modules
Imports System.Xml.Serialization
Imports Aricie.DNN.UI.WebControls.EditControls
Imports DotNetNuke.UI.WebControls

Namespace Aricie.DNN.Modules.LuceneSearch.Settings

    Public Class LuceneProviderConfig
        Inherits ProviderConfig


        Private _Provider As Object
        Private _DefaultResultTemplate As String

        <Browsable(False)> _
        Public ReadOnly Property Provider() As Object
            Get
                If _Provider Is Nothing Then
                    _Provider = MyBase.GetProvider
                End If
                Return _Provider
            End Get
        End Property

        Friend Sub ReplaceProvider(ByVal newProvider As Object)
            _Provider = newProvider
        End Sub


        <Category("LuceneSettings")> _
       Public ReadOnly Property IsGlossary() As Boolean
            Get
                If Me.Provider IsNot Nothing Then
                    Return TypeOf Me.Provider Is ILuceneFieldGlossary
                End If
                Return False
            End Get
        End Property

        <Category("LuceneSettings")> _
       Public ReadOnly Property IsSearchable() As Boolean
            Get
                If Me.Provider IsNot Nothing Then
                    Return TypeOf Me.Provider Is ISearchable
                End If
                Return False
            End Get
        End Property

        <Category("LuceneSettings")> _
       Public ReadOnly Property IsUpgrader() As Boolean
            Get
                If Me.Provider IsNot Nothing Then
                    Return TypeOf Me.Provider Is ILuceneSearchableUpgrade
                End If
                Return False
            End Get
        End Property

        <Category("LuceneSettings")> _
       Public ReadOnly Property IsStandAlone() As Boolean
            Get
                If Me.Provider IsNot Nothing Then
                    Return TypeOf Me.Provider Is ILuceneStandAloneSearchable
                End If
                Return False
            End Get
        End Property

        <Category("LuceneSettings")> _
        <Editor(GetType(CustomTextEditControl), GetType(EditControl))> _
        <LineCount(10)> _
        <Width(400)> _
        Public Property DefaultResultTemplate() As CData
            Get
                Return _DefaultResultTemplate
            End Get
            Set(ByVal value As CData)
                _DefaultResultTemplate = value
            End Set
        End Property


        Public Function AsGlossary() As ILuceneFieldGlossary
            Return DirectCast(Me.Provider, ILuceneFieldGlossary)
        End Function

        Public Function AsStandaloneSearchable() As ILuceneStandAloneSearchable
            Return DirectCast(Me.Provider, ILuceneStandAloneSearchable)
        End Function

    End Class
End Namespace

